#include "Common/ErrCollect/ErrCollect.h"
ErrCollectMgr::ErrCollectMgr()
{}

ErrCollectMgr::~ErrCollectMgr()
{}

bool ErrCollectMgr::Init(std::string preString)
{
	m_errPre = preString;
	return true;
}

bool ErrCollectMgr::CollectErr(char* buffer, uint32_t length)
{
	bool result = false;
	//bool retCode = false;
	std::string collectLog(buffer, length);
	std::string *pErr;

	ErrCollectMgr *plsgMgr = g_GetErrCollectMgr();
	MMOLOG_PROCESS_ERRLOG(plsgMgr != nullptr);
	MMOLOG_PROCESS_ERRLOG(plsgMgr->m_errLst.size() <= 100);

	pErr = plsgMgr->m_errLst.Add();
	MMOLOG_PROCESS_ERRLOG(pErr != nullptr);
	pErr->assign(plsgMgr->m_errPre + collectLog);
	result = true;
Exit0:
	return result;
}

bool ErrCollectMgr::PackErrLogs(ErrLogCollect &errCollect)
{
	if (m_errLst.size() == 0)
		return false;

	ERR_LOG_LIST *perrLst = nullptr;
	perrLst = errCollect.mutable_errlogs();
	if (perrLst == nullptr)
	{
		LogErrLogFmtPrint("LogicServerModuleMgr::OnTimer, error");
		return false;
	}
	perrLst->CopyFrom(m_errLst);
	m_errLst.Clear();
	return true;
}